#coding:utf-8

'''
======== train items ==========
     item_id(422858) item_geohash  item_category(620918 / 1054)
0  100002303          NaN           3368
1  100003592          NaN           7995

======== train users ==========

    user_id(20000)    item_id(4758484)  behavior_type(4) user_geohash  item_category(9557)            time
0  10001082             285259775              1            97lk14c           4076              2014-12-08 18
1  10001082              4368907               1              NaN             5503              2014-12-12 12

behavior_type 用户对商品的行为类型  包括浏览、收藏、加购物车、购买，对应取值分别是1、2、3、4。
user_geohash  用户位置的空间标识，可以为空
item_category 商品分类标识
'''
import pandas as pd

data_dir = "../DateSet/"
data_dir_train_item = data_dir + "tianchi_fresh_comp_train_item.csv"
data_dir_train_user = data_dir + "tianchi_fresh_comp_train_user.csv"

def read_data():
    train_item = pd.read_csv(data_dir_train_item) #620918
    train_user = pd.read_csv(data_dir_train_user) #23291027
    print("======== train items ==========")
    print(train_item.head(2))
    category_item = pd.unique(train_item["item_category"])
    print("total item category is: %s " % category_item)
    print("total item category length is: %s " % len(category_item))
    print("======== train users ==========")
    print(train_user.head(2))
    data_item = train_user.head(30)
    data_item.to_csv("data_item.csv")
    labels = train_user['item_id']
    category_user = pd.unique(train_user["user_id"]) # 20000 users
    print("total item category is: %s " % category_user)
    print("total item category length is: %s " % len(category_user))
    category_item = pd.unique(train_user["item_id"])
    print("total item category is: %s " % category_item)
    print("total item category length is: %s " % len(category_item))

def process_data():
    ''' 以时间为序，对数据进行重组， 返回数据和数据标签'''
    data_dir = "./data_item.csv"
    data = pd.read_csv(data_dir)
    dates = pd.to_datetime(data['time'])
    data.set_index(dates)
    new_data = pd.DataFrame(data,
                            columns=['user_id', 'item_id', 'behavior_type', 'item_category', 'user_geohash', 'time'])
    new_data = new_data.set_index(dates, drop=True)
    new_data_label = pd.DataFrame(new_data, columns=['item_id'], index=None)
    return new_data, new_data_label

def feature(data):
    data, data_label = data

    pass


test = pd.read_csv('./train/test_test_no_jiagou.csv')
print ("done")